import {HttpHelper} from "./HttpHelper";
import {Injectable} from "@angular/core";
import {CheckStataus, ManufactureEntry} from "./domains";


@Injectable()
export class ManufactureEntryService{

    entryUrl = "manufacture-entry";

    constructor(private httpHelper:HttpHelper){
    }

    getManufactureEntrys(page?:number,size?:number,noStore?:boolean,check?:CheckStataus):Promise<ManufactureEntry[]>{
        let url = this.entryUrl;
        if (page && size){
            url = url + `/?page=${page}&size=${size}`;
        }
        if (noStore!=null){
            url = url + `&no_stor=${noStore}`;
        }
        if (check){
            url = url + `&check=${check}`;
        }

        return this.httpHelper.getJson<ManufactureEntry[]>(url);
    }

    addManufactureEntry(entry:ManufactureEntry):Promise<ManufactureEntry>{
        return this.httpHelper.postToJson<ManufactureEntry>(this.entryUrl,entry);
    }

    checkManufactureEntry(entryId:number,quantity:number,reason?:string):Promise<ManufactureEntry>{
        let url = this.entryUrl+`/?entry=${entryId}&quantity=${quantity}`;
        return this.httpHelper.putToJson<ManufactureEntry>(url,reason);
    }

    intoStore(entryId:number,storeId:number) : Promise<ManufactureEntry> {
        let url = this.entryUrl+`/into_store/?entry=${entryId}&store=${storeId}`;
        return this.httpHelper.putToJson<ManufactureEntry>(url,null);
    }
}